/**
 * 
 */
package com.softqin.washer.activity;

import com.ab.activity.AbActivity;
import com.softqin.washer.R;
import com.softqin.washer.utils.DialogUtils;

import android.app.Activity;
import android.app.ProgressDialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @ClassName: BaseActivity
 * 
 * @Description: TODO(这里用一句话描述这个类的作用)
 * 
 * @author 杨守志
 * 
 * @date 2015-1-13 上午10:44:33
 */
public class BaseActivity extends AbActivity implements OnClickListener {
	
	private String TAG = BaseActivity.class.getSimpleName();
	
	protected static final int BASE_ID = 1;
	protected RelativeLayout titleLayout;
	protected TextView titleTv;
	protected ImageView backIv;
	protected TextView actionTv;
	protected ImageView titleIv;
	private Toast mToast;

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (mProgressDialog != null) {
			mProgressDialog = null;
		}
		titleTv = null;
		backIv = null;
		actionTv = null;
		titleIv = null;
		titleLayout = null;
	}

	/**
	 *初始化标题栏
	 */
	protected void initTitle() {
		titleLayout = (RelativeLayout) findViewById(R.id.public_title_linearlyout);
		titleTv = (TextView) findViewById(R.id.public_title_text);
		titleIv = (ImageView) findViewById(R.id.public_title_image);
		backIv = (ImageView) findViewById(R.id.public_title_back);
		if (backIv != null) {
			backIv.setOnClickListener(this);
		}
		actionTv = (TextView) findViewById(R.id.public_title_action);
		if (actionTv != null) {
			actionTv.setOnClickListener(this);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.public_title_back:
			finish();
			break;
		}
	}

	protected void showProgressDialog(String strTitle, int nStringId) {
		showProgressDialog(strTitle, getString(nStringId));
	}

	protected ProgressDialog mProgressDialog;

	protected void showProgressDialog(String strTitle, String strMessage) {
		if (mProgressDialog == null) {
			mProgressDialog = new ProgressDialog(BaseActivity.this);
			mProgressDialog.setCancelable(false);
		}
		mProgressDialog.setTitle(strTitle);
		mProgressDialog.setMessage(strMessage);
		if (!mProgressDialog.isShowing()) {
			mProgressDialog.dismiss();
		}
		mProgressDialog.show();
	}

	protected void dismissProgressDialog() {
		DialogUtils.dismissDialog(mProgressDialog);
	}

	protected void showMsg(String msg) {
		if (mToast == null) {
			mToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
		} else {
			mToast.setText(msg);
		}
		mToast.show();
	}

}
